package com.example;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller
public class TestController {

    @RequestMapping(method = RequestMethod.GET)
    public String hello(){
        return "test";
    }

    @RequestMapping("/index")
    public ResponseEntity<String> index(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin","*");
        String as = "hello";
        return new ResponseEntity<String>(as, HttpStatus.OK);
    }
    @GetMapping("/name")
    @ResponseBody
    public JSONObject getName(){
        JSONObject obj=new JSONObject();
        obj.put("name","张三");
        return obj;
    }

    @GetMapping("/jsonp")
    @ResponseBody
    public String jsonp(){
        return "change('我是来自第二个服务的内容')";
    }

}
